package term

import (
	"context"
	// "fmt"
	"strconv"

	"mall/common/globalkey"
	"mall/common/utils/pointy"
	"mall/service/backend/api/internal/svc"
	"mall/service/backend/api/internal/types"
	"mall/service/backend/common/i18n"

	// "github.com/sirupsen/logrus"
	"github.com/zeromicro/go-zero/core/logx"
)

type GetPredefinedListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGetPredefinedListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetPredefinedListLogic {
	return &GetPredefinedListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetPredefinedListLogic) GetPredefinedList() (resp *types.ProductPredefinedListResp, err error) {
	formDefault := []*types.MetaInfo{
		{
			Key:   pointy.GetPointer("status"),
			Value: pointy.GetPointer(strconv.Itoa(int(globalkey.StatusEnabled))),
		},
		{
			Key:   pointy.GetPointer("isVariation"),
			Value: pointy.GetPointer(strconv.Itoa(int(globalkey.StatusDisabled))),
		},
	}

	statusList := []*types.MetaInfo{
		{
			Key:   pointy.GetPointer("forbidden"),
			Name:  pointy.GetPointer("禁用"),
			Slug:  pointy.GetPointer("forbidden"),
			Value: pointy.GetPointer("0"),
		},
		{
			Key:   pointy.GetPointer("common"),
			Name:  pointy.GetPointer("正常"),
			Slug:  pointy.GetPointer("common"),
			Value: pointy.GetPointer("1"),
		},
		{
			Key:   pointy.GetPointer("deleted"),
			Name:  pointy.GetPointer("回收站"),
			Slug:  pointy.GetPointer("deleted"),
			Value: pointy.GetPointer("3"),
		},
	}

	metaKeyList := []*types.MetaInfo{
		{
			Key:  pointy.GetPointer("title"),
			Name: pointy.GetPointer("标题"),
			Slug: pointy.GetPointer("title"),
		},
		{
			Key:  pointy.GetPointer("keywords"),
			Name: pointy.GetPointer("关键词"),
			Slug: pointy.GetPointer("keywords"),
		},
		{
			Key:  pointy.GetPointer("description"),
			Name: pointy.GetPointer("描述"),
			Slug: pointy.GetPointer("description"),
		},
	}

	taxonomyList := []*types.MetaInfo{
		{
			Key:  pointy.GetPointer("category"),
			Name: pointy.GetPointer("分类"),
			Slug: pointy.GetPointer("1"),
		},
		{
			Key:  pointy.GetPointer("product_tag"),
			Name: pointy.GetPointer("标签"),
			Slug: pointy.GetPointer("21"),
		},
	}

	return &types.ProductPredefinedListResp{
		BaseDataInfo: types.BaseDataInfo{
			Success: true,
			Msg:     l.svcCtx.Trans.Trans(l.ctx, i18n.Success),
		},
		Data: types.ProductPredefinedListInfo{
			FormDefault:  formDefault,
			StatusList:   statusList,
			MetaKeyList:  metaKeyList,
			TaxonomyList: taxonomyList,
		},
	}, nil
}
